{% extends "/layout/login_layout.html" %}
{% block title %}
	登录
{% endblock %}
{% block container %}
<div class="box">
	<div class="container">
		<div>
			<div class="form-group">
				<label class="title" for="exampleInputEmail1">用户名：</label>
				<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
				<small id="emailHelp" class="form-text vaild-text">&nbsp</small>
			</div>
			<div class="form-group">
				<label class="title" for="exampleInputPassword1">密码：</label>
				<input type="password" class="form-control" id="exampleInputPassword1">
				<small id="passwordHelp" class="form-text vaild-text">&nbsp</small>
			</div>
			<div class="from-container">
				<button class="btn form-button" onclick="Submit()">确 认</button>
			</div>
		</div>
	</div>
</div>

<script>
	function Submit(){
		params = {
			unique_id: $("#exampleInputEmail1").val(),
			password: $("#exampleInputPassword1").val()
		}

		$("#emailHelp").html("&nbsp");
		$("#passwordHelp").html("&nbsp");

		if(["", undefined, null].includes(params.unique_id)){
			$("#emailHelp").html("用户名不能为空");
			return false;
		};

		if(["", undefined, null].includes(params.password)){
			$("#passwordHelp").html("密码不能为空");
			return false;
		};

		Requ.Login(params).then(function (response) {
			data = response.data.data;
			SessionControl.SetJsonSession("user", data["user_info"]);
			SessionControl.SetStringSession("token", data["token"]);
			// window.location.href='{{url_for("web_api.index")}}';
			URLControl.JumpUrl('{{url_for("web_api.index")}}');
		}).catch(function(error){
			code = error.response.data.code;
			ShowErrorMsg(ERRORCODE[code])
		});
	}

	function ShowErrorMsg(value){
		$(".alert").html(value);
		$(".alert").addClass("show");

		time = 5
		setInterval (function () {
			if(time>0){
				time = time - 1;
			}
			if(time==0){
				$(".alert").removeClass("show");
			}
		}, 1000);
	}
</script>
{% endblock %}